package com.ylbh.modules.share.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.banner.entity.AppHomeBanner;
import com.ylbh.modules.share.entity.WeChatShare;
import com.ylbh.modules.share.service.WeChatShareService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;

/**
 *
 * 微信分享
 * @author czx
 * @date 2019-05-13 16:42:05
 */
@RestController
@RequestMapping("share")
public class WeChatShareController {

    @Autowired
    private WeChatShareService weChatShareService;

    @ApiOperation("微信分享列表")
    @RequestMapping("queryShareList")
    @RequiresPermissions("share:queryShareList")
    public CommonResult<PageUtils> queryShareList(PageDTO pageDTO) {
        PageUtils list = weChatShareService.queryShareList(pageDTO);
        return Ref.ok(list);
    }

    @ApiOperation("微信分享详情")
    @RequestMapping("getShareDetailsById/{id}")
    @RequiresPermissions("share:getShareDetailsById")
    public CommonResult<WeChatShare> getShareDetailsById(@PathVariable(value = "id")String id) {
        WeChatShare share = weChatShareService.getShareDetailsById(id);
        return Ref.ok(share);
    }

    @SysLog("修改微信分享")
    @ApiOperation("修改微信分享")
    @RequestMapping("modifyShare")
    @RequiresPermissions("share:modifyShare")
    public CommonResult<Void> modifyShare(@RequestBody WeChatShare weChatShare) {
        weChatShareService.modifyShare(weChatShare);
        return Ref.ok();
    }

    @SysLog("新增微信分享")
    @ApiOperation("新增微信分享")
    @RequestMapping("addShare")
    @RequiresPermissions("share:addShare")
    public CommonResult<Void> addShare(@RequestBody WeChatShare weChatShare) {
        weChatShareService.addShare(weChatShare);
        return Ref.ok();
    }

    @ApiOperation("上传分享图片")
    @RequestMapping("uploadShare")
    public CommonResult<String> uploadShare(MultipartFile file){
        String url = weChatShareService.uploadShare(file);
        return Ref.ok(url);
    }

    @SysLog("删除分享")
    @ApiOperation("删除分享")
    @RequestMapping("removeShareById")
    @RequiresPermissions("share:removeShareById")
    public CommonResult<Void> removeShareById(@RequestBody String[] ids) {
        weChatShareService.removeShareById(Arrays.asList(ids));
        return Ref.ok();
    }

    @ApiOperation("分享规则")
    @GetMapping("queryShareRule")
    public CommonResult queryShareRule(PageDTO pageDTO) {
        PageUtils page = weChatShareService.queryShareRule(pageDTO);
        return Ref.ok(page);
    }

    @ApiOperation("分享规则详情")
    @GetMapping("getShareRuleById/{id}")
    public CommonResult getShareRuleById(@PathVariable Integer id) {
        AppHomeBanner vo = weChatShareService.getShareRuleById(id);
        return Ref.ok(vo);
    }

    @ApiOperation("修改分享规则详情")
    @PostMapping("modifyShareRuleById")
    public CommonResult modifyShareRuleById(@RequestBody AppHomeBanner appHomeBanner) {
        weChatShareService.modifyShareRuleById(appHomeBanner);
        return Ref.ok();
    }

    @ApiOperation("上传分享规则图片")
    @RequestMapping("uploadWeChat")
    public CommonResult<String> uploadWeChat(MultipartFile file){
        String url = weChatShareService.uploadWeChat(file);
        return Ref.ok(url);
    }

    @ApiOperation("新增分享规则")
    @PostMapping("addShareRule")
    public CommonResult addShareRule(@RequestBody AppHomeBanner appHomeBanner) {
        weChatShareService.addShareRule(appHomeBanner);
        return Ref.ok();
    }
}
